<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" th:with="title='系统设置',active='settings'">
<header th:replace="admin/header::headerFragment(${title},${active})"></header>
<link th:href="@{/admin/plugins/toggles/toggles.css}" rel="stylesheet"/>
<body class="fixed-left">
<div id="wrapper">
    <div th:replace="admin/header::header-body"></div>
    <div class="content-page">
        <div class="content">
            <div class="container">
                <div class="row">
                    <div class="col-sm-12">
                        <h4 class="page-title">系统设置</h4>
                    </div>
                    <div class="col-md-6">
                        <div class="panel panel-color panel-primary">
                            <div class="panel-heading">
                                <h3 class="panel-title">全局设置</h3>
                            </div>
                            <div class="panel-body">
                                <form class="form-horizontal" role="form" id="global-form">
                                    <div class="form-group">
                                        <label class="col-md-3 control-label">站点名称</label>
                                        <div class="col-md-9">
                                            <input type="text" class="form-control" name="site_title" placeholder="站点名称"
                                                   th:value="${options.site_title}" required="required" aria-required="true"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-md-3 control-label">站点描述</label>
                                        <div class="col-md-9">
                                            <input type="text" class="form-control" name="site_description" placeholder="站点描述"
                                                   th:value="${options.site_description}" required="required" aria-required="true"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-md-3 control-label">站点关键词</label>
                                        <div class="col-md-9">
                                            <input type="text" class="form-control" name="site_keywords" placeholder="站点关键词"
                                                   th:value="${options.site_keywords}" required="required" aria-required="true"/>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-md-3 control-label">建站时间</label>
                                        <div class="col-md-9">
                                        	<input type="text" class="form-control" name="site_time" placeholder="建站时间"
                                                   th:value="${options.site_time}" required="required" aria-required="true"/>
                                        </div>
                                    </div>
                                    
                                    <div class="form-group">
                                        <label class="col-md-3 control-label">站点声明</label>
                                        <div class="col-md-9">
                                        	<textarea type="text" class="form-control" name="site_statement" placeholder="站点声明"
                                                   th:utext="${options.site_statement}" required="required" aria-required="true"></textarea>
                                        </div>
                                    </div>
                                    
                                    <div class="form-group">
                                        <label class="col-md-3 control-label">转载声明</label>
                                        <div class="col-md-9">
                                        	<textarea type="text" class="form-control" name="site_reprinted" placeholder="转载站点声明"
                                                   th:utext="${options.site_reprinted}" required="required" aria-required="true"></textarea>
                                        </div>
                                    </div>
                                    
                                    <div class="form-group">
                                        <label class="col-md-3 control-label">搜索页最大查询结果数</label>
                                        <div class="col-md-9">
                                            <input type="text" class="form-control" name="site_max_search_size" placeholder="搜索页最大查询结果数"
                                                   th:value="${options.site_max_search_size}" required="required" aria-required="true"/>
                                        </div>
                                    </div>
                                    
                                    
                                    <input type="hidden" name="allow_install" id="allow_install"/>
                                    <div class="clearfix pull-right">
                                        <button type="button" class="btn btn-primary waves-effect waves-light" onclick="saveSetting()">
                                            保存设置
                                        </button>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>

                    <div class="col-md-6">
                        <div class="panel panel-color panel-inverse">
                            <div class="panel-heading">
                                <h3 class="panel-title">个性化设置</h3>
                            </div>
                            <div class="panel-body">
                                <form id="indivi-form" class="form-horizontal" role="form">
                                    <div class="form-group">
                                        <label class="col-md-3 control-label">微博账号</label>
                                        <div class="col-md-9">
                                            <input type="text" class="form-control" name="social_weibo" th:value="${options.social_weibo}"
                                                   placeholder="微博账号，不输入则不显示"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-md-3 control-label">博主昵称</label>
                                        <div class="col-md-9">
                                            <input type="text" class="form-control" name="site_nickname" th:value="${options.site_nickname}"
                                                   placeholder="昵称，不输入则不显示"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-md-3 control-label">博主职业</label>
                                        <div class="col-md-9">
                                            <input type="text" class="form-control" name="social_post" th:value="${options.social_post}"
                                                   placeholder="博主职业"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-md-3 control-label">现居地址</label>
                                        <div class="col-md-9">
                                            <input type="text" class="form-control" name="social_address" th:value="${options.social_address}"
                                                   placeholder="地址"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-md-3 control-label">我的邮箱</label>
                                        <div class="col-md-9">
                                            <input type="text" class="form-control" name="social_email" th:value="${options.social_email}"
                                                   placeholder="邮箱"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-md-3 control-label">我的qq</label>
                                        <div class="col-md-9">
                                            <input type="text" class="form-control" name="social_qq" th:value="${options.social_qq}"
                                                   placeholder="qq"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-md-3 control-label">我的微信</label>
                                        <div class="col-md-9">
                                            <input type="text" class="form-control" name="social_weixin" th:value="${options.social_weixin}"
                                                   placeholder="微信"/>
                                        </div>
                                    </div>
                                    <div class="clearfix pull-right">
                                        <button type="button" class="btn btn-primary waves-effect waves-light" onclick="saveIndiviSetting()">
                                            保存设置
                                        </button>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>

                    <div class="clearfix"></div>

<!--                     <div class="col-md-6"> -->
<!--                         <div class="panel panel-color panel-success"> -->
<!--                             <div class="panel-heading"> -->
<!--                                 <h3 class="panel-title">系统备份（备份文件包含附件和主题）</h3> -->
<!--                             </div> -->
<!--                             <div class="panel-body"> -->
<!--                                 <form id="backupForm" class="form-inline" role="form"> -->
<!--                                     <div class="form-group col-md-6"> -->
<!--                                         <input id="backup_dir" style="width: 100%;" class="form-control" placeholder="请输入备份存放的磁盘路径" required="" aria-required="true" type="text"/> -->
<!--                                     </div> -->

<!--                                     <button type="button" class="btn btn-success waves-effect waves-light m-l-10" onclick="backup('attach');">备份文件</button> -->
<!--                                     <button type="button" class="btn btn-danger waves-effect waves-light m-l-10" onclick="backup('db')">导出数据库SQL</button> -->
<!--                                 </form> -->
<!--                             </div> -->
<!--                         </div> -->
<!--                     </div> -->

                </div>
                <div th:replace="admin/footer :: footer-content"></div>
            </div>
        </div>
    </div>
</div>
<div th:replace="admin/footer :: footer"></div>
<script src="//cdn.bootcss.com/jquery-toggles/2.0.4/toggles.min.js"></script>
<script type="text/javascript">
    /*<![CDATA[*/
    var tale = new $.tale();

    /**
     * 保存全局设置
     */
    function saveSetting() {
        var param = $('#global-form').serialize();
        tale.post({
            url : ctxPath+'admin/setting',
            data: param,
            success: function (result) {
                if(result && result.success){
                    tale.alertOk('设置保存成功');
                } else {
                    tale.alertError(result.msg || '设置保存失败');
                }
            }
        });
    }

    /**
     * 保存个性化设置
     */
    function saveIndiviSetting() {
        var param = $('#indivi-form').serialize();
        tale.post({
            url : ctxPath+'admin/setting',
            data: param,
            success: function (result) {
                if(result && result.success){
                    tale.alertOk('设置保存成功');
                } else {
                    tale.alertError(result.msg || '设置保存失败');
                }
            }
        });
    }
    /**
     * 设置是否允许重新安装
     */
    function allow_reinstall(obj) {
        var this_ = $(obj);
        var on = this_.find('.toggle-on.active').length;
        var off = this_.find('.toggle-off.active').length;
        if (on == 1) {
            $('#allow_install').val(0);
        }
        if (off == 1) {
            $('#allow_install').val(1);
        }
    }

    /**
     * 系统备份
     * @param type
     */
    function backup(type) {
        var param = {
            bk_type: type,
            bk_path: $('#backup_dir').val()
        };
        tale.post({
            url : ctxPath+'admin/setting/backup',
            data: param,
            success: function (result) {
                if(result && result.success){
                    if(result.payload && result.payload.attach_path){
                        swal('备份成功', '您的附件备份在 <mark>'+ result.payload.attach_path +'</mark><br/><br/>' +
                            '主题备份存储在 <mark>'+ result.payload.theme_path +'</mark>', 'success');
                        $('#backup_dir').val('');
                    }
                    if(result.payload.sql_path){
                        window.location.href = ctxPath+'upload/' + result.payload.sql_path;
                    }
                } else {
                    tale.alertError(result.msg || '备份失败');
                }
            }
        });
    }

    $('.allow-1').toggles({
        on: true,
        text: {
            on: '开启',
            off: '关闭'
        }
    });
    $('.allow-0').toggles({
        off: true,
        text: {
            on: '开启',
            off: '关闭'
        }
    });
    /*]]>*/
</script>
</body>
</html>